package com.zhanglinwei.openApiClient.utils;

import com.zhanglinwei.common.utils.MD5Utils;

import java.util.HashMap;
import java.util.Map;

import static com.zhanglinwei.openApiClient.constants.OpenApiConstant.*;

public class OpenApiSigner {

    private OpenApiSigner(){}

    public static Map<String, String> signMap(String appKey, String appSecret) {
        return signMap(appKey, appSecret, String.valueOf(System.currentTimeMillis()));
    }

    public static Map<String, String> signMap(String appKey, String appSecret, String timestamp) {
        HashMap<String, String> signMap = new HashMap<>();
        signMap.put(APP_KEY_HEADER_KEY, appKey);
        signMap.put(SIGN_HEADER_KEY, sign(appKey, appSecret, timestamp));
        signMap.put(TIMESTAMP_HEADER_KEY, timestamp);
        return signMap;
    }

    public static String sign(String appKey, String appSecret, String timestamp) {
        return MD5Utils.md5Digest(appKey + appSecret + timestamp);
    }

}
